home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
UPC12BS1.ZIP
/
UUCICO
/
ULIBNMP.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-03
|
21KB
|
632 lines
/*--------------------------------------------------------------------*/
/* u l i b n m p . c */
/* */
/* OS/2 named pipe support for UUCICO */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* Changes Copyright (c) 1989-1993 by Kendra Electronic */
/* Wonderworks. */
/* */
/* All rights reserved except those explicitly granted by the */
/* UUPC/extended license agreement. */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* RCS Information */
/*--------------------------------------------------------------------*/
/*
* $Id: ulibnmp.c 1.7 1993/10/03 22:09:09 ahd Exp $
* $Log: ulibnmp.c $
* Revision 1.7 1993/10/03 22:09:09 ahd
* Use unsigned long to display speed
*
* Revision 1.6 1993/10/03 20:37:34 ahd
* Delete redundant error messages
*
* Revision 1.5 1993/09/29 04:49:20 ahd
* Delete obsolete variable
*
* Revision 1.4 1993/09/27 00:45:20 ahd
* OS/2 16 bit support
*
* Revision 1.3 1993/09/25 03:07:56 ahd
* Various small bug fixes
*
* Revision 1.2 1993/09/24 03:43:27 ahd
* General bug fixes to make work
*
* Revision 1.1 1993/09/23 03:26:51 ahd
* Initial revision
*
*
*/
/*--------------------------------------------------------------------*/
/* System include files */
/*--------------------------------------------------------------------*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <io.h>
#include <time.h>
/*--------------------------------------------------------------------*/
/* OS/2 include files */
/*--------------------------------------------------------------------*/
#define INCL_DOSDEVIOCTL
#define INCL_BASE
#include <os2.h>
#include <limits.h>
#ifndef __OS2__
typedef USHORT APIRET ; // Define older API return type
#endif
/*--------------------------------------------------------------------*/
/* UUPC/extended include files */
/*--------------------------------------------------------------------*/
#include "lib.h"
#include "ulibnmp.h"
#include "ssleep.h"
#include "catcher.h"
#include "commlib.h"
#include "pos2err.h"
/*--------------------------------------------------------------------*/
/* Global variables */
/*--------------------------------------------------------------------*/
currentfile();
static boolean carrierDetect = FALSE; /* Modem is not connected */
static boolean hangupNeeded = FALSE;
static BPS currentSpeed = 0;
static boolean passive;
#define FAR_NULL ((PVOID) 0L)
/*--------------------------------------------------------------------*/
/* Definitions of control structures for DOS API */
/*--------------------------------------------------------------------*/
static HPIPE pipeHandle;
static USHORT writeWait = 200;
static USHORT readWait = 50;
static int writes, reads, writeSpins, readSpins;
/*--------------------------------------------------------------------*/
/* p p a s s i v e o p e n l i n e */
/* */
/* Open a server pipe connection */
/*--------------------------------------------------------------------*/
#ifdef __TURBOC__
#pragma argsused
#endif
int ppassiveopenline(char *name, BPS baud, const boolean direct )
{
APIRET rc;
if (portActive) /* Was the port already active? */
closeline(); /* Yes --> Shutdown it before open */
#ifdef UDEBUG
printmsg(15, "ppassiveopenline: %s, %d", name, baud);
#endif
/*--------------------------------------------------------------------*/
/* Perform the open */
/*--------------------------------------------------------------------*/
#ifdef __OS2__
rc = DosCreateNPipe( (PSZ) "\\pipe\\uucp",
&pipeHandle,
NP_ACCESS_DUPLEX | NP_INHERIT | NP_NOWRITEBEHIND,
NP_NOWAIT | 1,
MAXPACK,
MAXPACK,
30000 );
#else
rc = DosMakeNmPipe( (PSZ) "\\pipe\\uucp",
&pipeHandle,
NP_ACCESS_DUPLEX | NP_INHERIT | NP_NOWRITEBEHIND,
NP_NOWAIT | 1,
MAXPACK,
MAXPACK,
30000 );
#endif
/*--------------------------------------------------------------------*/
/* Check the open worked. We translation the common obvious */
/* error of file in use to english, for all other errors are we */
/* report the raw error code. */
/*--------------------------------------------------------------------*/
if ( rc == ERROR_SHARING_VIOLATION)
{
printmsg(0,"Pipe %s already in use", name);
return TRUE;
}
else if ( rc )
{
printOS2error("DosCreateNPipe", rc );
return TRUE;
}
/*--------------------------------------------------------------------*/
/* Set baud rate */
/*--------------------------------------------------------------------*/
SIOSpeed(baud); // Just any old large number.
traceStart( name ); // Enable logging
portActive = TRUE; /* Record status for error handler */
passive = TRUE;
carrierDetect = FALSE; /* Modem is not connected */
return 0;
} /* ppassiveopenline */
/*--------------------------------------------------------------------*/
/* p W a i t F o r N e t C o n n e c t */
/* */
/* Wait for network connection */
/*--------------------------------------------------------------------*/
boolean pWaitForNetConnect(int timeout)
{
time_t stop;
stop = time( NULL ) + timeout;
do {
#ifdef __OS2__
APIRET rc = DosConnectNPipe( pipeHandle );
#else
APIRET rc = DosConnectNmPipe( pipeHandle );
#endif
if ( rc == 0 )
{
hangupNeeded = TRUE; /* Flag that the pipe is now dirty */
return TRUE;
}
else if ( rc == ERROR_PIPE_NOT_CONNECTED )
ssleep(5);
else {
printOS2error("DosConnectNPipe", rc );
return FALSE;
} /* else */
} while( (stop > time( NULL )) && ! terminate_processing );
return FALSE;
} /* pWaitForNetConnect */
/*--------------------------------------------------------------------*/
/* p a c t i v e o p e n l i n e */
/* */
/* Open a client pipe connection */
/*--------------------------------------------------------------------*/
#ifdef __TURBOC__
#pragma argsused
#endif
int pactiveopenline(char *name, BPS baud, const boolean direct )
{
APIRET rc;
#ifdef __OS2__
ULONG action;
#else
USHORT action;
#endif
if (portActive) /* Was the port already active? */
closeline(); /* Yes -->